<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8"/>
    <title>查看人员信息</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css"/>
</head>
<body>
<input id="user_id" th:value="${user.id}" hidden="hidden"/>
<div id="view"></div>
</body>
<script src="/static/layui/layui.all.js"></script>

<script id="user_view" type="text/html">
    <form class="layui-form" action="/user/update" method="post" style="margin-top: 15px">
        <input name="id" value="{{d.id}}" hidden="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="userName" value="{{d.userName}}" disabled autocomplete="off" class="layui-input"/>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="1" disabled title="男" {{d.sex == 1 ? "checked":""}}/>
                <input type="radio" name="sex" value="0" disabled title="女" {{d.sex == 0 ? "checked":""}}/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-inline">
                <input type="text" name="age" value="{{d.age}}" disabled autocomplete="off" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Email</label>
            <div class="layui-input-inline">
                <input type="text" name="email" value="{{d.email}}" disabled autocomplete="off" class="layui-input"/>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" value="{{d.phone}}"  disabled autocomplete="off" class="layui-input"/>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">启用</label>
            <div class="layui-input-block">
                <input type="checkbox" name="enable" disabled lay-skin="switch" {{d.enable ? "checked":""}} />
            </div>
        </div>

    </form>

</script>
<script>
    layui.use(['laytpl','form'], function(){
        var laytpl = layui.laytpl;
        var form = layui.form;

        layui.$.ajax({
            type:"get",
            async:false,
            url:"/user/get/" + layui.$('#user_id').val(),
            success:function(data){
                if(data.status ){
                    var data = data.data;
                    var getTpl = user_view.innerHTML
                        ,view = document.getElementById('view');

                    laytpl(getTpl).render(data, function(html) {
                        view.innerHTML = html;
                    });
                }
            }
        });
        form.render(); //更新全部
    });

</script>
</html>